package com.microstream.lift.client;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class Lift implements EntryPoint {

	private final GreetingServiceAsync greetingService = GWT
			.create(GreetingService.class);

	private VerticalPanel mainPanel = new VerticalPanel();
	private FlexTable stocksFlexTable = new FlexTable();
	private HorizontalPanel addPanel = new HorizontalPanel();

	private ArrayList<String> stocks = new ArrayList<String>();

	public void onModuleLoad() {
		sendNameToServer();
	}

	private void sendNameToServer() {
		greetingService.greetServer("", new AsyncCallback<ArrayList>() {
			public void onFailure(Throwable caught) {
			}

			/*
			public void onSuccess(String result) {
				stocksFlexTable.setText(0, 0, "User List");

				int row = stocksFlexTable.getRowCount();
				String symbol = "Table Count";
				stocks.add(symbol);				
				stocksFlexTable.setText(row, 0, symbol);

				stocksFlexTable.getRowFormatter().addStyleName(0,
						"watchListHeader");
				mainPanel.add(stocksFlexTable);

				RootPanel.get("userList").add(mainPanel);
				stocksFlexTable.addStyleName("watchList");
			}
			*/

			@Override			
			public void onSuccess(ArrayList result) {
				stocksFlexTable.setText(0, 0, "User List");

				
				for(int i=0;i<result.size(); i++) {
					String symbol = result.get(i).toString();
					int row = stocksFlexTable.getRowCount();
					stocks.add(symbol);
					stocksFlexTable.setText(row, 0, symbol);
				}

				stocksFlexTable.getRowFormatter().addStyleName(0,
						"watchListHeader");
				mainPanel.add(stocksFlexTable);

				RootPanel.get("userList").add(mainPanel);
				stocksFlexTable.addStyleName("watchList");
				
			}
		});
	}
}
